﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

namespace WebApplication10.App_Code
{
    public class Industry
    {
        public int IndustryID { get; set; }
        public string Name { get; set; }

        public static List<Industry> GetIndustries() // Select.
        {
            List<Industry> results = new List<Industry>();
            SqlConnection conn = null;

            try
            {
                conn = new SqlConnection();
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["JobDBString"].ConnectionString;
                conn.Open();
                SqlCommand comm = new SqlCommand();
                comm.Connection = conn;
                comm.CommandText = "Select * from Industry";
                SqlDataReader dr = comm.ExecuteReader();

                while (dr.Read())
                {
                    Industry i = new Industry();
                    i.IndustryID = (int)dr["IndustryID"];
                    i.Name = (string)dr["Name"];
                    results.Add(i);
                }
                dr.Close();
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return results;
        }
    }
}